//常规登录界面
<template>
  <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <h1>千锋管理系统</h1>
        <i @click="tiaotwo" :class="['diannao','iconfont','icon-erweimajiaobiao']"></i>
        <el-form-item label="用户名" prop="usename">
            <el-input type="text" v-model="ruleForm.usename" autocomplete="off">
            </el-input>
        </el-form-item>
        <el-form-item label="密码" prop="checkPass">
            <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="age">
            <el-input v-model.number="ruleForm.age"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button class="btn" type="primary" @click="submitForm('ruleForm')">提交</el-button>
        </el-form-item>
        <div class="smallbox">
            <img src="@/assets/imgs/2.png" alt="" width="20px">
            <span @click="tiao">切换短信登录</span>
        </div>
    </el-form>
</template>

<script>

import {mapState} from 'vuex' 
import {mapMutations} from 'vuex' 
var validatePass = (rule, value, callback) => {
        let regexpq = /^[a-zA-Z0-9_-]{3,16}$/
        if (regexpq.test(value)) {
            callback();
        } else {
            callback('请输入正确的用户名格式');
        }
    };
    var validatePass2 = (rule, value, callback) => {
        let regexpq = /^[a-zA-Z0-9_-]{3,16}$/
        if (regexpq.test(value)) {
            callback();
        }else {
            callback('请输入正确的密码');
        }
    };
    var checkAge = (rule, value, callback) => {
        if (!value) {
            return callback('验证码不能为空');
        }
        setTimeout(() => {
            if (!Number.isInteger(value)) {
                callback(new Error('请输入数字值'));
            } else {
                if (value < 18) {
                    callback(new Error('必须年满18岁'));
                } else {
                    callback();
                }
            }
        }, 1000);
    };
export default {
    data() {
        return {
            ruleForm: {
                usename: '',
                checkPass: '',
                age: ''
            },
            rules: {
                usename: [
                    { validator: validatePass, trigger: 'blur' }
                ],
                checkPass: [
                    { validator: validatePass2, trigger: 'blur' }
                ],
                age: [
                    { validator: checkAge, trigger: 'blur' }
                ]
            }
        };
    },
    methods: {
        ...mapMutations('login',['TIAODX','TIAODXTWO']),
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    alert('submit!');
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        tiao(){
            this.TIAODX()
        },
        tiaotwo(){
            this.TIAODXTWO()
        }
    },
    computed:{
        ...mapState('login',['flage'])
    },
}
</script>

<style lang="less">
    .demo-ruleForm {
    background-color: rgba(0,0,0,.3);
    color: #fff;
    width: 400px;
    border-radius: 5px;
    padding: 85px 0px 50px ;
    position: absolute;
    z-index: 10;
    top: 25%;
    right:10%;
    .diannao{
            position: absolute;
            font-size: 50px;
            top: -2px;
            right: -2px;
            cursor: pointer;
        }
    label{
        color: #fff;
        text-align: right;
    }
    .el-input{
        width: 250px;
        height: 38px;
        /deep/ .el-input__inner{
            width: 250px;
            height: 38px;
            padding: 0px 15px;
        }
    }
    .btn{
        width: 250px;
        margin-top: 15px;
    }
    h1 {
        line-height: 1;
        text-align: center;
        font-size: 2em;
        margin-bottom: 65px;
    }
    .smallbox{
        display: flex;
        flex-direction: center;
        justify-content: center;
        vertical-align: middle;
        span{
            text-align: center;
            text-decoration: underline;
            cursor: pointer;
        }
    }
    
}

</style>